from rest_framework import serializers
from myapp.models import *



class SalarySer(serializers.ModelSerializer):
    user = serializers.PrimaryKeyRelatedField(queryset=UserModel.objects.all())
    user_name = serializers.SerializerMethodField()

    def get_user_name(self,obj):
        return obj.user.username


    class Meta:
        model = Salary
        fields ='__all__'


class ApplyTyoeSer(serializers.ModelSerializer):

     class Meta:
         model = ApplyTypeModel
         fields = '__all__'


class FlowSer(serializers.ModelSerializer):
    apply = serializers.PrimaryKeyRelatedField(queryset=ApplyTypeModel.objects.all())
    apply_name = serializers.SerializerMethodField()

    def get_apply_name(self,obj):
        return obj.apply.name
    class Meta:
        model = FlowModel
        fields = '__all__'


class ApproverSer(serializers.ModelSerializer):
    user = serializers.PrimaryKeyRelatedField(queryset=UserModel.objects.all())
    user_name = serializers.SerializerMethodField()

    def get_user_name(self, obj):
        return obj.user.username
    class Meta:
        model = ApproverModel
        fields = '__all__'


class MaterialSer(serializers.ModelSerializer):
    class Meta:
        model = MaterialManageModel
        fields = '__all__'